import type { BrowserProfile, BrowserSession } from "@common/models";
import { invokeRPC } from "./helpers";

export * as quickMessage from "./quickMessage";
export * as xhs from "./xhs";
export * as settings from "./settings";

export const createBrowserSession = () =>
  invokeRPC({
    rpcName: "browser.createBrowserSession",
    rpcParams: {},
    receiver: "plugin",
  }) as Promise<{
    browserSessionId: string;
  }>;

export const openBrowserSession = (sessionId: string) =>
  invokeRPC({
    rpcName: "browser.openBrowserSession",
    rpcParams: { sessionId },
    receiver: "plugin",
  }) as Promise<{
    browserSessionId: string;
  }>;

export const closeBrowserSession = (browserSessionId: string) => {
  return invokeRPC({
    rpcName: "browser.closeBrowserSession",
    rpcParams: { browserSessionId },
    receiver: "plugin",
  });
};

export const deleteBrowserSession = (browserSessionId: string) => {
  return invokeRPC({
    rpcName: "browser.deleteBrowserSession",
    rpcParams: { browserSessionId },
    receiver: "plugin",
  });
};

export const syncBrowserSessions = () => {
  return invokeRPC({
    rpcName: "app.syncSessions",
    rpcParams: {},
    receiver: "plugin",
  }) as Promise<{ sessions: BrowserSession[] }>;
};

export const loadBrowserProfiles = () =>
  invokeRPC({
    rpcName: "browser.loadProfiles",
    receiver: "plugin",
    rpcParams: {},
  }) as Promise<{ profiles: BrowserProfile[] }>;

export const hasRHChromium = () =>
  invokeRPC({
    rpcName: "browser.hasRHChromium",
    receiver: "plugin",
    rpcParams: {},
  }) as Promise<boolean>;
